package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.AccessProductBackVo;
import com.zhijian.warehouse.manage.entity.vo.request.AccessProductExtendVo;
import com.zhijian.warehouse.manage.entity.vo.request.AccessProductRecordSaveOrUpdateVo;
import com.zhijian.warehouse.manage.entity.vo.request.AccessProductRecordSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.AccessProductRecordVo;
import com.zhijian.warehouse.manage.service.AccessProductRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仪器领用归记录 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-28 17:42:45
 */
@Slf4j
@Controller
@Api(tags = "app仪器扫码/感应 领用归还")
@RequestMapping("/app")
public class AppAccessProductRecordController {

	@Autowired
    private AccessProductRecordService service;
    
    /**
     * 归还
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/back")
    @ApiOperation("归还")
    public boolean back(@RequestBody AccessProductBackVo param) {
        log.info("{} - {}| back info", this.getClass().getSimpleName(), param);
        return service.back(param);
    }
    
    /**
     * 延长领用时间
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/extend")
    @ApiOperation("延长领用天数")
    public boolean extend(@RequestBody AccessProductExtendVo param) {
        log.info("{} - {}| extend info", this.getClass().getSimpleName(), param);
        return service.extend(param);
    }
    
    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record")
    @ApiOperation("新增")
    public boolean insert(@RequestBody AccessProductRecordSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }
    

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/access/product/record/{id}")
    @ApiOperation("根据id查询")
    public AccessProductRecordVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record/page")
    @ApiOperation("分页查询")
    public Page<AccessProductRecordVo> selectByCondition(@RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
        * 列表查询
        *
        * @param param
        * @return
    */
    @Response
    @PostMapping("/access/product/record/list")
    @ApiOperation("列表查询")
    public List<AccessProductRecordVo> selectList(@RequestBody(required = false) AccessProductRecordSearchVo param) {
            if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
            log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
            return service.selectList(param);
        }
        
}
